<template>
  <!--录入数据-->
  <el-dialog
    v-model="visible"
    :title="title"
    width="30%"
    @closed="$emit('closed')"
    destroy-on-close
  >
    <el-form
      :model="produceForm"
      ref="addProduceForm"
      label-width="auto"
      label-position="right"
    >
      <el-form-item label="生产数量" prop="equipmentNum">
        <el-input-number
          v-model="produceForm.equipmentNum"
          :min="0"
          autocomplete="off"
        ></el-input-number>
      </el-form-item>
      <el-form-item></el-form-item>
      <!-- <el-form-item
        label="附件"
        v-if="produceForm.num > produceForm.contractNum"
        style="margin-top: 15px"
      >
        <sc-upload-file
          v-model="produceForm.otherFileList"
          :limit="10"
          :multiple="false"
          tip="最多上传10个文件,单个文件不要超过20M"
        >
          <el-button type="primary" plain icon="el-icon-upload"
            >上传附件</el-button
          >
        </sc-upload-file>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="submmit()" :loading="isSaveing"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>
<script>
export default {
  emits: ['success', 'closed'],
  name: 'enterData',
  data () {
    return {
      title: "",
      visible: false,
      isSaveing: false,
      produceForm: {
        id: "",//设备id
        schedulingId: '',//排产id
        equipmentNum: 0,//生产数量
        // otherFileList: [],//附件
      },
    }
  },
  methods: {
    open (data) {
      console.log(data)
      this.visible = true
      this.produceForm.id = data.id
      this.produceForm.schedulingId = data.schedulingId
    },
    submmit () {
      this.$refs.addProduceForm.validate(async (valid) => {
        if (valid) {
          // let fileType = ''
          // this.produceForm.otherFileList.map(item => {
          //   if (item.url) {
          //     let arr = item.url.split('.')
          //     let type = arr[arr.length - 1]
          //     // fileType  1图片 2文件
          //     let imageType = 'jpg/png/jpeg/svg'
          //     if (imageType.includes(type)) {
          //       fileType = 1
          //     } else {
          //       fileType = 2
          //     }
          //     item.fileType = fileType
          //     item.fileName = item.name
          //   }
          // })
          this.isSaveing = true
          var result = await this.$API.produce.equipment.handleEnterData.post(this.produceForm)
          this.isSaveing = false
          if (result.code == 200) {
            this.$emit('success')
            this.visible = false
            this.$message.success("操作成功")
          } else {
            this.$alert(result.message, "提示", { type: 'error' })
          }
        }
      })
    },
  }
}
</script>